package com.linser.gistools.refactoring.javafx.treeitem;

import javafx.scene.Node;
import javafx.scene.control.TreeItem;

import java.io.File;

/**
 * @author: linser
 * @Desc: 文件类型的 TreeItem
 * @create: 2024-01-10
 */
public class FileTreeItem extends TreeItem<String> {
    private File treeItemFile;

    private String favoriteTag;

    public FileTreeItem() {
        super();
    }

    public FileTreeItem(String value) {
        super(value);
    }

    public FileTreeItem(File file) {
        super(file.getParent() == null?file.getPath():file.getName());
        this.treeItemFile = file;
    }
    /**
     * Creates a TreeItem with the value property set to the provided object, and
     * the graphic set to the provided Node.
     *
     * @param value The object to be stored as the value of this TreeItem.
     * @param graphic The Node to show in the TreeView next to this TreeItem.
     */
    public FileTreeItem(String value, final Node graphic) {
        super(value,graphic);
    }

    //重写叶子方法，如果该文件不是目录，则返回真
    @Override
    public boolean isLeaf() {

        return this.treeItemFile.isFile();
    }

    /**
     * @return the file
     */
    public File getFile() {
        return this.treeItemFile;
    }

    public String getFavoriteTag(){
        return this.favoriteTag;
    }
    public void setFavoriteTag(String favoriteTag){
        this.favoriteTag = favoriteTag;
    }
}
